package java111;

import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

public class Day21 {
    //https://ac.nowcoder.com/acm/problem/213471
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int[] arr = new int[n];
            int[] res = new int[n];
            for(int i = 0; i < n; i++){
                arr[i] = i+1;
            }
            int left = 0, right = n-1, count = 0;
            for(int i = 0; i < n; i++){
                if(count % 2 == 0){
                    res[i] = arr[left++];
                } else {
                    res[i] = arr[right--];
                }
                System.out.print(res[i] + " ");
                count++;
            }
        }
    }

    //https://www.nowcoder.com/practice/635ff765d4af45b5bf8e3756ed415792?tpld=134&tqld=33860&ru=/exam/oj
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            int b = in.nextInt();
            TreeSet<Integer> set = new TreeSet<>();
            for(int i = 0; i < a + b; i++){
                set.add(in.nextInt());
            }
            for(int tmp : set){
                System.out.print(tmp + " ");
            }
//            Arrays.sort(arr);
//            int tmp = 0;
//            for(int i = 0; i < a+b; i++){
//                if(arr[i] != tmp){
//                    System.out.print(arr[i] + " ");
//                    tmp = arr[i];
//                }
//            }
        }
    }

    //https://www.nowcoder.com/practice/82297b13eebe4a0981dbfa53dfb181fa
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.next();
        int len = str.length();
        int[][] dp = new int[len][len];
        // dp[i][j] 表示字符串[i, j]区间内，最长回文子序列的长度
        for(int i = len-1; i >= 0; i--){
            for(int j = 0; j < len; j++){
                if(i > j){
                    dp[i][j] = 0;
                } else if(i == j){
                    dp[i][j] = 1;
                } else {
                    if(str.charAt(i) == str.charAt(j)){
                        dp[i][j] = dp[i+1][j-1] + 2;
                    } else {
                        dp[i][j] =  Math.max(dp[i+1][j], dp[i][j-1]);
                    }
                }
            }
        }
        System.out.println(dp[0][len-1]);
    }
}
